package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()) {
           /* UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册");
            Statement statement = connection.createStatement();
            String sqlzc = "insert into userinfo(username, password, nickname, age) " +
                            "value ('"+userInfo.getUsername()+"','"+userInfo.getPassword()+"','"+userInfo.getNickname()+"',"+userInfo.getAge()+");";
            int i = statement.executeUpdate(sqlzc);
            if (i > 0) {
                System.out.println("注册成功");
            } else if (i<0) {
                System.out.println("注册失败");
            }
            Scanner scanner=new Scanner(System.in);
            System.out.println("输入用户名");
            String nn=scanner.nextLine();
            System.out.println("输入密码");
            String pp=scanner.nextLine();*/
            UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎登录", "登录");
            Statement statement = connection.createStatement();
            String sqlcx="select username,password from userinfo " +
                    "where username='" + userInfo.getUsername() + "' " +
                    "and password='" + userInfo.getPassword() + "'";
            ResultSet resultSet = statement.executeQuery(sqlcx);
            if(resultSet.next()){
                System.out.println("登录成功");
            }else{
                System.out.println("登录成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
